// SPDX-FileCopyrightText: 2023-2025 Sangfor Technologies Inc.
// SPDX-License-Identifier: Mulan PSL v2
package com.geniusai.aip.auth.service.impl;

/**
 * @author hml14563
 * @date 2021/5/6
 */
public enum MemoryNumEnum {
    /**
     * PeraByte to GigaByte
     */
    Pi("Pi", 1024 * 1024),
    /**
     * TeraByte to GigaByte
     */
    Ti("Ti", 1024),
    /**
     * GigaByte
     */
    Gi("Gi", 1),
    /**
     * MillionByte to GigaByte
     */
    Mi("Mi", 1.0 / 1024),
    /**
     * KilByte to GigaByte
     */
    Ki("Ki", 1.0 / 1024 / 1024),

    m("m", 1.0 / 1024 / 1024 / 1024 / 1024);

    private String format;
    private double value;

    MemoryNumEnum(String format, double value) {
        this.format = format;
        this.value = value;
    }

    public static double getFormat(String format) {
        MemoryNumEnum[] memoryNumEnums = MemoryNumEnum.values();
        for (MemoryNumEnum numEnum : memoryNumEnums) {
            if (numEnum.format().equals(format)) {
                return numEnum.value();
            }
        }
        return 1;
    }

    public String format() {
        return format;
    }

    public double value() {
        return value;
    }
}
